package com.example.controller;

import com.example.entity.result.Result;
import com.example.entity.result.ResultBean;
import com.example.exception.OperatorException;
import com.example.exception.ServiceException;
import com.example.utils.DataUtils;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestController;

/**
 * 异常处理
 */
@RestController
public class BaseHandleException {

    @ExceptionHandler
    public ResultBean baseHandleException(ServiceException e) {
        return DataUtils.getResultBean(Result.ERROR,"",e.getMessage());
    }

    @ExceptionHandler
    public ResultBean baseHandleException(OperatorException e) {
        return DataUtils.getResultBean(e.getCode(),"",e.getMessage());
    }
}
